package com.longdaji.decoration.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.longdaji.decoration.R;
import com.longdaji.decoration.bean.Feedback;
import com.longdaji.decoration.utils.TimeUtil;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Kanade on 2018/5/3 0003.
 */

public class FeedbackAdapter extends RecyclerView.Adapter<FeedbackAdapter.ViewHolder> {

    private List<Feedback.UserViewBean> mUserViewList = new ArrayList<>();

    private Context mContext;

    public FeedbackAdapter(List<Feedback.UserViewBean> userViewBeanList) {
        this.mUserViewList = userViewBeanList;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_content)
        TextView tvContent;
        @BindView(R.id.tv_date)
        TextView tvDate;
        @BindView(R.id.tv_status)
        TextView tvStatus;
        @BindView(R.id.tv_back_content)
        TextView tvBackContent;
        @BindView(R.id.tv_back_date)
        TextView tvBackDate;
        @BindView(R.id.tv_back_status)
        TextView tvBackStatus;
        @BindView(R.id.view_division)
        View viewDevision;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mContext == null) {
            mContext = parent.getContext();
        }
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_feedback, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Feedback.UserViewBean userView = mUserViewList.get(position);
        holder.tvContent.setText(userView.getViewContent());
//        holder.tvDate.setText(String.valueOf(userView.getCreateTime()));
        holder.tvDate.setText(TimeUtil.getDateToString(userView.getCreateTime()));
        holder.tvStatus.setText("已提交");

        holder.tvBackContent.setText(userView.getReplyContent());
        holder.tvBackDate.setText(TimeUtil.getDateToString(userView.getReplyTime()));
        holder.tvBackStatus.setText("已回复");

        if (TextUtils.equals("0", userView.getIsReply())) {
            holder.viewDevision.setVisibility(View.GONE);
            holder.tvBackContent.setVisibility(View.GONE);
            holder.tvBackDate.setVisibility(View.GONE);
            holder.tvBackStatus.setVisibility(View.GONE);
        } else {
            holder.viewDevision.setVisibility(View.VISIBLE);
            holder.tvBackContent.setVisibility(View.VISIBLE);
            holder.tvBackDate.setVisibility(View.VISIBLE);
            holder.tvBackStatus.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public int getItemCount() {
        return mUserViewList.size();
    }

//    private String progressIsReply(String isReply) {
//        if (TextUtils.equals("0", isReply)) {
//            return "已提交";
//        } else {
//            return "已回复";
//        }
//    }

    public void setData(List<Feedback.UserViewBean> list) {
        this.mUserViewList.clear();
        this.mUserViewList.addAll(list);
        notifyDataSetChanged();
    }


//    public static String getDateToString(long milSecond) {
//        if (milSecond == 0)
//            return null;
//        Date date = new Date(milSecond);
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        return format.format(date);
//    }
}
